<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class WxuserWxcard extends Model
{
    //
    protected $dateFormat = 'Y-m-d H:i:s';
    protected $table = 'wxusers_wxcards';
    protected $guarded  = [];

    public function wxusers()
    {
        return $this->belongsTo(Wxuser::class,'id_wxusers','id');
    }

    public function wxcard()
    {
        return $this->belongsTo(Wxcard::class,'id_wxcards','id');
    }

    /*
     *
     */
    public function getCardTime($value)
    {

    }

    public function getCardStatus(bool $value)
    {
        $data[0]=[
            'status'=>0,
            'desc'=>'已使用'
        ];
        $data[1]=[
            'status'=>1,
            'desc'=>'待使用'
        ];

        $k =  $value ? 1:0;
        return $data[$k];
    }

    public function getCardTimeStatus($end_time)
    {
        //$de =$end_time->$begin_time;
        if($end_time<time()) return ['status'=>0,'desc'=>'已过期'];

        if($end_time - 3600*24*3>=time()); return ['status'=>1,'desc'=>date('Y-m-d',$end_time)];

        return ['status'=>2,'desc'=>date('Y-m-d',$end_time)];
    }
}
